package com.oba.king.sysmanager;

import java.util.List;

import com.oba.base.dao.BaseDao;
import com.oba.base.util.Util;

public class ModuleDao extends BaseDao {

	private static String FIND_MODULE_BY_GROUP = "select moduleid from groupmodule where groupid = ?";

	public List<Module> findAll() {
		return find("from Module order by serial");
	}

	public List<Module> findModuleByGroup(UserGroup group) {
		List<Long> moduleIdList = jdao.queryForList(FIND_MODULE_BY_GROUP, new Object[] { group.getId() }, Long.class);
		StringBuffer sb = new StringBuffer();
		sb.append("from Module m where m.id in ");
		sb.append(Util.idsFormat(moduleIdList));
		sb.append(" order by m.serial");
		System.out.println(sb.toString());
		return find(sb.toString());
	}
}
